package com.homegoods.designer.ui.activity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.homegoods.designer.R;
import com.homegoods.designer.databinding.DesignerActivityApplyDesignerBinding;
import com.homegoods.designer.ui.fragments.ApplyEnterpriseFragment;
import com.homegoods.designer.ui.fragments.ApplyFreedomDesignerFragment;
import com.homegoods.aroutercomment.ARouterPath;
import com.jakewharton.rxbinding2.widget.RxRadioGroup;
import com.kedll.library.adapter.AbFragmentPagerAdapter;
import com.kedll.library.base.MyBaseFragmentActivity;
import com.kedll.library.mvp.BasePresenter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author QiQi
 * @ClassName: DesignerApplyActivity
 * @date 2018/10/6
 * @description 申请认证设计师
 */
@Route(path = ARouterPath.PATH_DESIGNER_APPLY)
public class DesignerApplyActivity extends MyBaseFragmentActivity<DesignerActivityApplyDesignerBinding, BasePresenter> {
    @Override
    protected void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        List<Fragment> fragments = new ArrayList<>();
        ApplyEnterpriseFragment enterpriseFragment = new ApplyEnterpriseFragment();
        ApplyFreedomDesignerFragment freedomDesignerFragment = new ApplyFreedomDesignerFragment();
        fragments.add(enterpriseFragment);
        fragments.add(freedomDesignerFragment);

        AbFragmentPagerAdapter adapter = new AbFragmentPagerAdapter(getSupportFragmentManager(), fragments);
        mBinding.viewpager.setAdapter(adapter);
        mBinding.viewpager.setPagingEnabled(false);
    }

    @Override
    protected void initToolBar(Bundle savedInstanceState) {
        super.initToolBar(savedInstanceState);
        setTitle("申请认证设计师");
    }

    @Override
    protected BasePresenter getPresenter() {
        return null;
    }

    @Override
    protected int getLayout() {
        return R.layout.designer_activity_apply_designer;
    }

    @SuppressLint("CheckResult")
    @Override
    protected void initEvent() {
        RxRadioGroup.checkedChanges(mBinding.rgSwitch)
                .skipInitialValue()
                .compose(bindToLifecycle())
                .subscribe(checkedId -> {
                    if (checkedId == R.id.rb_enterprise) {
                        mBinding.viewpager.setCurrentItem(0, false);
                    } else if (checkedId == R.id.rb_person) {
                        mBinding.viewpager.setCurrentItem(1, false);
                    }
                });

    }
}
